package com.journey.org.ui.home.beauty

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.material.tabs.TabLayout
import com.journey.org.BR
import com.journey.org.R
import com.journey.org.databinding.FragmentBeautyGirlBinding
import com.journey.org.ui.home.beauty.dayline.DayLineFragment
import com.journey.org.ui.home.beauty.gankio.GankIoGirlFragment
import com.mvvmhabit.org.base.BaseFragment
import com.mvvmhabit.org.base.BaseFragmentPagerAdapter

/**
 * @Date: 2020/11/24 11:07
 * @Author:小妖
 * @Description: 美女
 */
class BeautyGirlFragment : BaseFragment<FragmentBeautyGirlBinding, BeautyGirlViewModel>() {

    private val mFragment = ArrayList<Fragment>()

    private val mTitle = ArrayList<String>()

    override fun initVariableId(): Int = BR.viewModel

    override fun initViewModel(): Class<BeautyGirlViewModel> = BeautyGirlViewModel::class.java

    override fun initContentView(
        inflater: LayoutInflater?,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): Int = R.layout.fragment_beauty_girl

    override fun initData() {
        super.initData()

        mFragment.add(GankIoGirlFragment())
        mTitle.add("干货美女")

        mFragment.add(DayLineFragment())
        mTitle.add("天行美女")

        initAdapter()
    }

    private fun initAdapter() {
        mBinding.layoutGirlViewpager.offscreenPageLimit = 1
        val adapter = BaseFragmentPagerAdapter(activity!!.supportFragmentManager, mFragment, mTitle)
        mBinding.layoutGirlViewpager.adapter = adapter
        mBinding.layoutGirlTab.setupWithViewPager(mBinding.layoutGirlViewpager)
        mBinding.layoutGirlViewpager.addOnPageChangeListener(
            TabLayout.TabLayoutOnPageChangeListener(
                mBinding.layoutGirlTab
            )
        )
    }
}